home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Collection of Tools & Utilities
/
Collection of Tools and Utilities.iso
/
clipper
/
nfsrc21.zip
/
FTTEXT.C
< prev
next >
Wrap
C/C++ Source or Header
|
1992-10-17
|
38KB
|
1,293 lines
/*
* File......: TEXT.C
* Author....: Brice de Ganahl and Steve Larsen
* CIS ID....: 76370,1532
* Date......: $Date: 17 Oct 1992 16:25:16 $
* Revision..: $Revision: 1.7 $
* Log file..: $Logfile: C:/nanfor/src/fttext.c_v $
*
* This is an original work by Brice de Ganahl and Steve Larsen
* and is placed in the public domain.
*
* Doc headers by Glenn Scott, Don Caton, and Steve Larsen
*
* Extensively revised by Steve Larsen
*
* Modification history:
* ---------------------
*
* $Log: C:/nanfor/src/fttext.c_v $
*
* Rev 1.7 17 Oct 1992 16:25:16 GLENN
* Leo cleaned up the documentation, including an errant SEEALSO
* reference.
*
* Rev 1.6 03 Oct 1992 02:07:38 GLENN
* Minor adjustments to file header block.
*
* Rev 1.5 03 Oct 1992 02:03:44 GLENN
* Major modifications by Steve Larsen, as follows:
*
* Brice laid some wonderful groundwork with his initial release of
* these functions, however I needed more capability. With his per-
* mission, I have made the following additions/changes to Rev. 1.4:
*
* - Eliminated the problem of memory for buffers being re-allocated every
* time a file got used.
* - Further reduced memory impact by converting from extend system memory
* allocation techniques to virtual memory. To accomplish this, we
* use the Clipper v5.01 r1.29 variants of the "_v" undocumented
* internal functions. If these functions change in future releases, you
* will need to locate them herein and make the appropriate changes.
*
* NOTE: these functions allocate and deallocate virtual memory on an
* "as-needed" basis. If your application makes heavy and frequent use
* of those functions that perform a lot of buffering (ft_fInsert(),
* ft_fDelete() and ft_fWrite()), you might consider modifying the memory
* management scheme used herein, that is, allocate the required buffers
* only once upon the first call to these functions, then recycle them.
* - Added the ability to specify file open mode.
* - Added a function to write to a record, which through a switch can either
* over-write the current record, or insert a new one.
* - Added functions to insert, delete and append a specified number of lines.
* - Fixed the existing functions so that they properly handle "trailers",
* that is, a case where the last chars in a file are not CRLF delimited.
* - Provided checking for the possibility that the file might be terminated
* with ^Z (1Ah), if so, ignoring it (providing consistency with non-^Z
* terminated files). This only occurs on the last record of a file.
* - Eliminated a potential problem if one were to issue an ft_fUse() prior
* actually opening any files.
* - Replaced the original C parsing logic to determine the end-of-line (CRLF)
* with an optimized assembler routine. This bypassed a significant
* performance hit.
* - The original header (FTTEXT.h) file in now incorporated in this one file.
* This is not necessarily an enhancement, more like laziness.
* - Provided the (followup) author with his very first C experience!
*
* Steve Larsen, Dec. 7, 1991 CIS 76370,1532
*
* - Function changes/additions (refer to the individual doc headers for
* details):
*
* FT_FSELECT( [ < nArea > ] ) -> nArea
* FT_FUSE( [ < cFile > ][, < nMode > ] ) -> nHandle | NIL
* FT_FWRITELN( < cData > [, < lInsert > ] ) -> NIL
* FT_FINSERT( [ < nLines > ] ) -> NIL
* FT_FDELETE( [ < nLines > ] ) -> NIL
* FT_FAPPEND( [ < nLines > ] ) -> NIL
*
* Internal Steve Larsen revisions:
*
* 12/07/91 Original rework
* 02/13/92 Fixed _findeol(), FT_FREADLN() and FT_FGOBOT() to
* better handle files with CRLF, LF, ^Z or nothing
* at the EOF. Previously, under some conditions the
* last record was chopped by a character, depending
* on the last character(s).
* 05/02/92 Fixed buffering and VMM allocation problem with
* FT_FGOBOT().
* 08/26/92 Correcting problem when appending blank lines to an
* empty file (ft_fAppend() and ft_fWriteLn()).
*
*
* Rev 1.4 17 Aug 1991 15:31:08 GLENN
* Don Caton fixed some spelling errors in the doc
*
* Rev 1.3 15 Aug 1991 23:08:36 GLENN
* Forest Belt proofread/edited/cleaned up doc
*
* Rev 1.2 29 Apr 1991 08:02:12 GLENN
* Minor adjustments to documentation block
*
* Rev 1.1 29 Apr 1991 08:00:26 GLENN
* ft_flastrec() -- name was longer than 10 characters so linkers couldn't
* find the symbol. Just hacked off the last "c" so it is really
* ft_flastre(). Sorry, folks. -- Glenn
*
* Rev 1.0 01 Apr 1991 01:02:48 GLENN
* Nanforum Toolkit
*
*/
/* Notes:
The Clipper internal functions used seem to be stable across
versions but nothing is guaranteed. These functions begin
with _t, are used for file I/O, and are compatible with their
ANSI counterparts (just strip the _t and you have the ANSI name).
See text.h for the prototypes.
This revision utilizes the in-line assembler feature found in MSC
6.0. If compiling with TurboC substitute "_asm" with "asm".
I compile these functions with the following MicroSoft C parameters:
cl /c /AL /Od /Zl /Zi /FPa /Gs /W3 text.c
Note that the /Od defeats optimization and is necessary only for
compatibility with Blinker, Warplink, etc. If you are not overlaying
this code you may want to change this to /Oalt. Likewise, the
/Zi is for symbolic debugging info which you will want to omit in
any final compiles.
Some sample Clipper code which would use these functions is listed
below. It will print out the contents of this file.
ft_fuse( "text.c" )
do while !ft_feof()
? ft_freadln()
ft_fskip()
enddo
ft_fuse()
*/
/* up this number if you need more than 10 text file areas */
#define TEXT_WORKAREAS 10
#include "extend.h"
#include "stdio.h"
#include "share.h"
#include "fcntl.h"
#define b_size 1024
#define c_size 4096
#ifndef SIZE_T
#define SIZE_T
typedef unsigned int size_t;
#endif
void pascal ft_fseek( void );
void pascal ft_fuse( void );
void pascal ft_fselect( void );
void pascal ft_fgotop( void );
void pascal ft_frecno( void );
void pascal ft_fgobot( void );
void pascal ft_fskip( void );
void pascal ft_freadln( void );
void pascal ft_flastre( void );
void pascal ft_feof( void );
void pascal ft_fgoto( void );
void pascal ft_fwritel( void );
void pascal ft_fdelete( void );
void pascal ft_fappend( void );
int _findeol( char *buf, int buf_len ); /* in-line ASM */
int _findbol( char *buf, int buf_len ); /* in-line ASM */
/*void _ftwrite( char *buf, int insert ); (replaced below) */
long _filewrite( long read1, long read2, long end1, long end2,
char *c, char *c2 );
long _ft_skip( int recs );
extern int _tclose( int );
extern int _tcreat( char*, int );
extern int _terror;
extern long _tlseek( int, long, int );
extern int _topen( char*, int );
extern int _tread( int, char*, int );
extern int _twrite( int, char*, int );
extern int _tcommit( int );
/* extern int strlen( char* ); */
extern int _vAlloc( int, int );
extern char *_vLock( int );
extern void _vUnLock( int );
extern void _vFree( int );
static long recno[TEXT_WORKAREAS];
static long offset[TEXT_WORKAREAS];
static int handles[TEXT_WORKAREAS];
static int area = 0;
static long last_rec[TEXT_WORKAREAS];
static long last_off[TEXT_WORKAREAS];
static long lastbyte[TEXT_WORKAREAS];
static int isEof[TEXT_WORKAREAS];
/* $DOC$
* $FUNCNAME$
* FT_FUSE()
* $CATEGORY$
* File I/O
* $ONELINER$
* Open or close a text file for use by the FT_F* functions